package com.weayer.controller;

import com.weayer.dto.ResponseResult;


import com.weayer.request.CheckVerificationCodeDTO;
import com.weayer.request.SendVerificationCodeDTO;
import com.weayer.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: Api服务 - 乘客 - 验证码controller
 * @author: Weayer
 **/
@RestController
public class VerificationCodeController {
    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * @Description: 验证码生成
     * @Param: [verificationCodeDTO]
     * @return: com.weayer.dto.ResponseResult
     **/
    @GetMapping("/verification-code")
    public ResponseResult verificationCode(@Validated @RequestBody SendVerificationCodeDTO sendVerificationCodeDTO){
//        int i = 1 / 0;
        String passengerPhone = sendVerificationCodeDTO.getPassengerPhone();
        return verificationCodeService.generatorCode(passengerPhone);
    }

    /**
     * @Description: 验证码校验
     * @Param: [verificationCodeDTO]
     * @return: com.weayer.dto.ResponseResult
     **/
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@Validated @RequestBody CheckVerificationCodeDTO checkVerificationCodeDTO){
        String passengerPhone = checkVerificationCodeDTO.getPassengerPhone();   // 手机号
        String verificationCode = checkVerificationCodeDTO.getVerificationCode(); // 验证码
        return verificationCodeService.checkCode(passengerPhone, verificationCode);
    }
}
